// promise.any

Promise.myany = function(promises) {
    let len = promises.length
    let result = []
    return new Promise((resolve, rejected) =>{
        if(len == 0) {
            rejected()
        }
    
        for(let i = 0; i < len; i++) {
            Promise.resolve(promises[i]).then(res => {
                resolve(res)
            }).catch(err => {
                result.push(err)
                if(result.length == len) {
                    rejected(result)
                }
            })
        }
    }) 
}



// let a = function() {
//     return new Promise((resolve, rejected) => {
//         console.log('123');
//         setTimeout(() => {
//             resolve('123')
//         }, 2000)
//     })
// }

// let b = function() {
//     return new Promise((resolve, rejected) => {
//         console.log('123');
//         setTimeout(() => {
//             resolve('333')
//         }, 1000)
//     })
// }



// // pro.then(res => {
// //     console.log(res);
// // })



// Promise.any([]).then(res => {
//     console.log(res);
// })

var resolved = Promise.resolve(42);
var rejected = Promise.reject(-1);
var alsoRejected = Promise.reject(Infinity);

Promise.myany([resolved, rejected, alsoRejected]).then(function (result) {
  console.log(result); // 42
});

Promise.myany([rejected, alsoRejected]).catch(function (results) {
  console.log(results); // [-1, Infinity]
});